<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link href="/static/css/bootstrap.css" rel="stylesheet">
    <script type="text/javascript" src="/static/js/jquery-3.2.1.js"></script>
</head>
<body>
<form method="post" id="form">
    <input type="hidden" name="id" value="${user.id}">
性别:<input type="radio" name="sex" value="男">男
    <input type="radio" name="sex" value="女">女<br>
    手机号:<input type="text" name="telephone" value="${user.telephone}" required><br>
    生日：<input type="date" name="birthday" value="<fmt:formatDate value='${user.birthday}' pattern='yyyy-MM-dd'/>" required><br>
    用户名:<input type="text" name="username" value="${user.username}"required><br>
    密码:<input type="text"  name="password" value="${user.password}" required>
    <input type="button" value="修改" onclick="update()">
</form>
</body>
<script>
    $(function () {
        $("[name='sex']").val(['${user.sex}']);
    })
    function update() {
        if($("[name='telephone']").val().length!=11){
            alert("请输入正确的手机号");
            return;
        }
        $.post(
            "/updateUser",
            $("#form").serialize(),
            function (mag) {
                if (mag){
                    alert("修改成功");
                    location.href = "list";
                }
            }
        )
    }
</script>
</html>